<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="app">
  <!--注意组件不要闭合写。会出现下面的内容不出现还没报错！-->
  <code-wind ref="aaa"></code-wind>
  <button @click="funApp">按钮</button>
</div>
<template id="cpn">
  <div>
    {{cpnName}}
  </div>
</template>
<script>
  var vm = new Vue({
    el: '#app',
    methods: {
      funApp() {
        /*
          $refs获取在子组件中标记了ref属性的子组件对象。
        */
        console.log(this.$refs);
        console.log(this.$refs.aaa.cpnName);
        this.$refs.aaa.cpnMethod();
      }
    },
    components: {
      codeWind: {
        template: "#cpn",
        data() {
          return {
            cpnName: "我是子组件的name属性~！"
          }
        },
        methods: {
          cpnMethod() {
            console.log("我是子组件的方法~！");
          }
        }
      }
    }
  })
</script>
</body>
</html>